﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace UpperComputer.WPF.Entry.Converters
{
    public class DateTimeToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }
            DateTime dateTime = (DateTime)value;
            string dateTimeStr = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
            return dateTimeStr;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }
            DateTime dateTime = DateTime.Parse(value.ToString());
            return dateTime;
        }
    }
}
